﻿namespace Odyssey.Consul.Features.Rules
{
    public class ACLRule
    {
        public static string AgentBuild(string segment, EnumPolicyControlLevel enumPolicyControlLevel, bool prefix = false)
        {
            return Build(EnumResource.Agent, segment, enumPolicyControlLevel, prefix);
        }

        public static string EventBuild(string segment, EnumPolicyControlLevel enumPolicyControlLevel, bool prefix = false)
        {
            return Build(EnumResource.Event, segment, enumPolicyControlLevel, prefix);
        }

        public static string KeyBuild(string segment, EnumPolicyControlLevel enumPolicyControlLevel, bool prefix = false)
        {
            return Build(EnumResource.Key, segment, enumPolicyControlLevel, prefix);
        }

        public static string NodeBuild(string segment, EnumPolicyControlLevel enumPolicyControlLevel, bool prefix = false)
        {
            return Build(EnumResource.Node, segment, enumPolicyControlLevel, prefix);
        }

        public static string QueryBuild(string segment, EnumPolicyControlLevel enumPolicyControlLevel, bool prefix = false)
        {
            return Build(EnumResource.Query, segment, enumPolicyControlLevel, prefix);
        }

        public static string ServiceBuild(string segment, EnumPolicyControlLevel enumPolicyControlLevel, bool prefix = false)
        {
            return Build(EnumResource.Service, segment, enumPolicyControlLevel, prefix);
        }

        public static string SessionBuild(string segment, EnumPolicyControlLevel enumPolicyControlLevel, bool prefix = false)
        {
            return Build(EnumResource.Session, segment, enumPolicyControlLevel, prefix);
        }

        public static string Build(EnumResource enumResource, string segment, EnumPolicyControlLevel enumPolicyControlLevel, bool prefix = false)
        {
            return $"{enumResource.ToString().ToLower()}{(prefix ? "_prefix" : "")} \"{segment}\" {{ policy = \"{enumPolicyControlLevel.ToString().ToLower()}\" }}";
        }
    }
}
